<?php

namespace App\Console\Commands;

use App\System\Cis\Services\DailyWagePlanningTaskService;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

class PaySalary extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'PaySalary';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '发工资计划任务';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $start_time = config('global.payNoStartTime');
        $end_time = config('global.payNoEndTime');
        $start_time = date("Y-m-d",strtotime($start_time) + 172800);//设置的开始时间加二天
        $end_time = date("Y-m-d",strtotime($end_time)+ 259200);//设置结束时间加三天
        $date = date("Y-m-d");//当前时间
        if($start_time <= $date && $date < $end_time)
        {//不发放工资
            return ;
        }

        $a = new DailyWagePlanningTaskService();
        $r = $a->settlementDayWages();
        $path = storage_path('logs/crontab.log');
        Log::useDailyFiles($path);
        if($r)
        {

            Log::info('发工资计任任务执行失败：原因：'.$r);
        }
        else
        {
            Log::info('发工资计任任务执行成功');
        }
    }
}
